package com.huiying.mapper;

import com.huiying.entity.entity.Read;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: lsh
 * @Date: 2024/12/01/22:10
 * @Description: 用户阅读记录表
 */

@Mapper
public interface ReadMapper {

    @Select("insert into `read`(item_id, item_type, user_id, read_time)" +
            "values (#{itemId},#{itemType},#{userId},#{readTime})")
    void insert(Read read);

    @Select("select count(*) from `read` where item_id = #{demandId} and item_type = #{contentType}")
    Long getReadCountByDemandId(@Param("demandId") long demandId,
                                @Param("contentType") String contentType);

    @Select("select distinct item_id from `read`" +
            "where user_id = #{userId} and item_type = #{demand};")
    List<Long> getContentId(@Param("userId") Long userId,
                            @Param("demand") String demand);

    @Delete("delete from `read` where item_id = #{demandId} and item_type = #{demand}")
    void deleteByItemId(@Param("demandId") Long demandId,
                        @Param("demand") String demand);
}
